#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

void my_reserve(int left, int right, string& str)
{
    while (left < right)
    {
        swap(str[left], str[right]);
        left++;
        right--;
    }
}


int main() {
    string str;
    getline(cin, str);
    int n = str.size();
    int left = 0;
    int right = 0;
    while (right < n)
    {
        if (str[right] == ' ')
        {
            my_reserve(left, right - 1, str);
            left = right + 1;
        }
        else if (str[right] == '.')
        {
            my_reserve(left, right, str);
            left = right + 1;
        }
        right++;
    }
    reverse(str.begin(), str.end());
    cout << str;
    return 0;
}

int main() {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int prev = arr[0];
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        if (arr[i] > prev)
        {
            sum += (arr[i] - prev);
            prev = arr[i];
        }
        else
        {
            prev = arr[i];
        }
    }
    cout << sum << endl;
    return 0;
}

int max_many(int& n, int& m, int& a)
{
    int ret = 0;
    while (n >= 2 && m)
    {
        ret += a;
        n -= 2;
        m--;
    }
    return ret;
}

int main() {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    int ret = 0;
    if (a > b)
    {
        ret += max_many(n, m, a);
        ret += max_many(m, n, b);
    }
    else
    {
        ret += max_many(m, n, b);
        ret += max_many(n, m, a);
    }
    cout << ret << endl;
    return 0;
}

int main() {
    long long n, m, a, b;
    cin >> n >> m >> a >> b;
    long long sum = 0;
    for (long long i = 0; i <= min(n / 2, m); i++)
    {
        long long j = min(n - i * 2, (m - i) / 2);
        sum = max(sum, a * i + b * j);
    }
    cout << sum << endl;
    return 0;
}


int main() {
    string str1;
    string str2;
    string str3;
    getline(cin, str1);
    getline(cin, str2);
    int arr[255] = { 0 };
    for (auto s : str2)
    {
        arr[s] = 1;
    }
    for (auto s : str1)
    {
        if (arr[s])
        {
            continue;
        }
        str3 += s;
    }
    cout << str3 << endl;
    return 0;
}

struct ListNode {
    int val;
    struct ListNode* next;
    ListNode(int x) :
        val(x), next(NULL) {
    }
}; 
class Solution {
public:
    size_t ListNodeLength(ListNode* pHead)
    {
        ListNode* cur = pHead;
        int ret = 0;
        while (cur)
        {
            cur = cur->next;
            ret++;
        }
        return ret;
    }

    ListNode* NewHead(ListNode* pHead, int n)
    {
        ListNode* cur = pHead;
        while (n--)
        {
            cur = cur->next;
        }
        return cur;
    }

    ListNode* FindFirstCommonNode(ListNode* pHead1, ListNode* pHead2)
    {
        int n1 = ListNodeLength(pHead1);
        int n2 = ListNodeLength(pHead2);
        ListNode* cur1 = nullptr;
        ListNode* cur2 = nullptr;
        if (n1 > n2)
        {
            cur1 = NewHead(pHead1, n1 - n2);
            cur2 = pHead2;
        }
        else
        {
            cur2 = NewHead(pHead2, n2 - n1);
            cur1 = pHead1;
        }
        while (cur1 && cur2)
        {
            if (cur1 == cur2)
            {
                return cur1;
            }
            cur1 = cur1->next;
            cur2 = cur2->next;
        }
        return nullptr;
    }
};

int main() {
    int n;
    string str;
    cin >> n >> str;
    long long arr[3] = { 0 };
    for (auto s : str)
    {
        if (s == 's')
        {
            arr[0]++;
        }
        else if (s == 'h')
        {
            arr[1] += arr[0];
        }
        else if (s == 'y')
        {
            arr[2] += arr[1];
        }
    }
    cout << arr[2] << endl;
    return 0;
}